﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;

namespace DrawTools
{
    [Serializable]
    public class DrawWater : DrawRectangle
	{
        //public bool animatingFlag = false;//设定动画标志
        //public Bitmap gifImage = new Bitmap(@"F:\myfile\HMI\DrawTools\bin\Debug\" + "/Resources/TDS100W.jpg");
        private const int showIndexCount = 2;
        private int showIndex = 1; //动画播放索引
        private int cube;

        public int Cube
        {
            get { return cube; }
            set { cube = value; }
        }

        public int ShowIndex
        {
            get { return showIndex; }
            set { showIndex = value; }
        }

		public DrawWater() : this(0, 0, 1, 1)
		{
		}

        public DrawWater(int x, int y, int width, int height)
            : base()
        {
            Rectangle = new Rectangle(x, y, width, height);
            Initialize();
        }

        public override void SaveToStream(System.Runtime.Serialization.SerializationInfo info,
            int orderNumber)
        {
            info.AddValue("cube" + orderNumber.ToString(), Cube);

            base.SaveToStream(info, orderNumber);
        }

        public override void LoadFromStream(System.Runtime.Serialization.SerializationInfo info,
            int orderNumber)
        {
            Cube = info.GetInt32("cube" + orderNumber.ToString());

            base.LoadFromStream(info, orderNumber);
        }

        /// <summary>
        /// Clone this instance
        /// </summary>
        public override DrawObject Clone(DrawObject drawObject)
        {
            return base.Clone(drawObject);
        }


        public override void Draw(Graphics g)
        {           
            try
            {
                Pen pen = new Pen(Color, PenWidth);
                switch (showIndex)
                {
                    case 1:
                        g.DrawImage(Image.FromFile(Common.FunctionClass.getRunPath()
                            + @"\Resources\iphone.png"), 
                            DrawRectangle.GetNormalizedRectangle(Rectangle));
                        break;
                    case 2:
                        g.DrawImage(Image.FromFile(Common.FunctionClass.getRunPath()
                            + @"\Resources\iphone.png"),
                            DrawRectangle.GetNormalizedRectangle(Rectangle));
                        break;
                }
                
                pen.Dispose();
                showIndex++; //改变索引
                if (showIndex > showIndexCount)
                {
                    showIndex = 1;
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            
        }


	}
}
